#include "glFPS.h"

#include "..\glut\glut.h"

float glFPS(bool bAvg, int32 nAvg)
{
    static int curr_time = 0;
    static int prev_time = 0;
    static int fps_counter = 0;
    static float fps = 0.0f;

    curr_time = glutGet(GLUT_ELAPSED_TIME);

    if (bAvg)
    {
        if (fps_counter++ > nAvg)
        {
            fps = nAvg * 1000.0f / (curr_time - prev_time);
            prev_time = curr_time;
            fps_counter = 0;
        }
    }
    else
    {
        fps = 1000.0f / (curr_time - prev_time);
        prev_time = curr_time;
    }  

    return fps;
}
